package com.landeqing.dao.impl;

import com.landeqing.dao.BanJiDao;
import com.landeqing.model.BanJi;
import com.landeqing.model.Student;
import com.landeqing.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.omg.Messaging.SYNC_WITH_TRANSPORT;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository
public class BanJiDaoImpl implements BanJiDao {

    public  List<BanJi> getList() {
        try {
            SqlSession sqlSession = MyBatisUtils.getSqlSession();
            List<BanJi> list=sqlSession.selectList("com.landeqing.model.banjiModel.getList");
            sqlSession.close();
            return list;
        }catch (Exception i){
            i.printStackTrace();
        }
        return null;

    }

    public BanJi getBanJiId(Integer id) {
        try {
            SqlSession sqlSession = MyBatisUtils.getSqlSession();
           BanJi banJi=sqlSession.selectOne("com.landeqing.model.banjiModel.getById",id);
            sqlSession.close();
            return banJi;
        }catch (Exception i){
            i.printStackTrace();
        }
        return null;
    }

    public  static  void  main(String []args){
        BanJiDaoImpl banJiDao=new BanJiDaoImpl();

//        List<BanJi> list=banJiDao.getList();
//        for (BanJi c :list) {
//            System.out.println("班级名称："+c.getClassName());
//        }
       BanJi banJi= banJiDao.getBanJiId(1);
     List<Student> list=  banJi.getStudents();
        for (Student s:list
             ) {
            System.out.println(s.getName());

        }

    }
}
